package com.lgc.webtest.common.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 自定义配置器适配器
 */
@Configuration
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter { //Spring Boot2.0的版本（创建的时候自动选择的这个版本），然后编译器告诉我WebMvcConfigurerAdapter已过时了

    @Bean
    public HandlerInterceptor getInnerApiInterceptor(){
        return new InnerApiInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 对所有资源拦截但是排除/demo/showCart
//        registry.addInterceptor(new InnerApiInterceptor())
//                .addPathPatterns("/**")
//                .excludePathPatterns("/demo/showCart");

        //根据controller进行拦截
        registry.addInterceptor(getInnerApiInterceptor())
                .addPathPatterns("/integral/**")
                .addPathPatterns("/sync/**")
                .addPathPatterns("/task/**")
                .addPathPatterns("/test/**")
                .addPathPatterns();

        //其他自定义拦截器
//        registry.addInterceptor(new otherInterceptor())
//                .addPathPatterns("/cart/**")
//                .addPathPatterns("/order/**");
        super.addInterceptors(registry);
    }
}
